"""
Case Type   : 系统内部使用工具
Case Name   : gs_ctl restart指定-o "OPTIONS"启动是否报错
Create At   : 2021/01/18
Owner       : opentestcase015
Description :
    1.关闭运行正常的集群
    2.使用-o option参数重启数据库
    3.恢复集群状态
Expect      :
    1.关闭运行正常的集群成功
    2.使用-o option参数重启数据库失败
    3.恢复集群状态成功
History     :
"""

import unittest

from testcase.utils.CommonSH import CommonSH
from testcase.utils.Constant import Constant
from testcase.utils.Logger import Logger
from yat.test import Node
from yat.test import macro

LOG = Logger()


class LogicalReplication(unittest.TestCase):
    def setUp(self):
        LOG.info('----this is setup------')
        LOG.info(
            '---Opengauss_Function_Tools_gs_ctl_Case0036开始执行-----')
        self.constant = Constant()
        self.env_path = macro.DB_ENV_PATH
        self.instance_path = macro.DB_INSTANCE_PATH
        self.user_node = Node('PrimaryDbUser')
        self.sh_primary = CommonSH('PrimaryDbUser')

    def test_system_internal_tools(self):
        LOG.info('-------关闭正在运行的集群-------')
        is_stop = self.sh_primary.stop_db_cluster()
        self.assertTrue(is_stop)

        LOG.info('-------使用-o option参数重启数据库------')
        excute_cmd = f'''
                source {self.env_path};
                gs_ctl restart -D {self.instance_path} -M primary -o option; 
                    '''
        LOG.info(excute_cmd)
        msg = self.user_node.sh(excute_cmd).result()
        LOG.info(msg)
        self.assertIn(self.constant.argument_error, msg)

    def tearDown(self):
        LOG.info('----this is tearDown------')
        LOG.info('----恢复集群状态------')
        is_start = self.sh_primary.start_db_cluster()
        LOG.info(is_start)
        LOG.info(
            '-----Opengauss_Function_Tools_gs_ctl_Case0036执行完成---')
